package com.software.yh.service.grpc;

import com.software.proto.HelloProto;
import com.software.proto.HelloServiceGrpc;
import io.grpc.Channel;
import net.devh.boot.grpc.client.inject.GrpcClient;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;

/**
 * @author: lsy
 * @date: 2025/11/5
 * @version: 1.0
 */
@Service
public class HelloGrpcService {

    @GrpcClient("grpc-server")
    private Channel channel;

    private HelloServiceGrpc.HelloServiceBlockingStub helloServiceStub;

    @PostConstruct
    public void init() {
        helloServiceStub = HelloServiceGrpc.newBlockingStub(channel);
    }

    public String getHello(String name) {
        HelloProto.HelloResponse hello = helloServiceStub.hello(HelloProto.HelloRequest.newBuilder().setName(name).build());
        return hello.getMessage();
    }

}
